import React,{Component,PropTypes} from 'react';
import {redirect,backward} from 'lib/utils';
import Baselist from 'components/Baselist';
import Crumb from 'components/Crumb'
import API,{} from 'lib/api';

import {Card,Form,Input, Button, notification } from 'antd';
import './style.less';

const FormItem = Form.Item;


class AddGenre extends Component{
    constructor(props){
        super(props);

        this.state={
            hasImg:true ,       // 有图片
            crumb:[
                {href:"/",title:"首页"},
                {href:"/",title:"商品类型"},
                {href:"/",title:"添加类型"}
            ]
        }
    };


    componentDidMount(){

        if(this.props.routeParams.id){
            /* API.fetch("",{id:id},resp=>{  */
                const initData = {name:"新品上市"}
                this.props.form.setFieldsValue(initData);
            /* })*/
        }

    }


    openNotificationWithIcon = (type,title,msg="") => {
        notification[type]({
            message: title,
            description: msg,
        });
    };



    handleSubmit = (e) => {
        e.preventDefault();
        this.props.form.validateFields((err, values) => {
            if (!err) {
                console.log('Received values of form: ', values);
                this.openNotificationWithIcon('success',"保存成功",)
            }
        });
    };


    render(){
        const { getFieldDecorator } = this.props.form;
        return(
            <Baselist>
                <Crumb crumb={this.state.crumb}/>
                <Card title="类型信息" noHovering={true}>
                    <Form onSubmit={this.handleSubmit} className="common-info">
                        <FormItem
                            label="名称"
                            labelCol={{ span: 4 }}
                            wrapperCol={{ span: 8 }}
                        >
                            {getFieldDecorator('name', {
                                rules: [{ required: true, message: '请输入商品类型名称' }],
                            })(
                                <Input placeholder="请输入商品类型名称"/>
                            )}
                        </FormItem>

                        <FormItem
                            wrapperCol={{ span: 8, offset: 4 }}
                        >
                            <Button type="primary" htmlType="submit">
                                保存
                            </Button>
                        </FormItem>
                    </Form>
                </Card>
            </Baselist>

        )
    }
};

export default Form.create()(AddGenre);